#ifndef __MAX7219_H
#define __MAX7219_H

#include "GPIO.h"
#include "headfile.h"

#define MAX7219_BIT_DIS 0x0f
#define MAX7219_BIT_FU 0x0A

class MAX7219
{
private:
    GPIO CLK;
    GPIO CS;
    GPIO DIN;
    /* data */
    void write_byte(uint8_t);
    void write_data(uint8_t, uint8_t);

public:
    MAX7219(Pin_enum din, Pin_enum clk, Pin_enum cs)
    {
        DIN = GPIO(din, OUT_PP);
        CLK = GPIO(clk, OUT_PP);
        CS = GPIO(cs, OUT_PP);
        DIN.write(1);
        CLK.write(1);
        CS.write(1);
        write_data(0x09, 0xff);
        write_data(0x0a, 0x0f);
        write_data(0x0b, 0x07);
        write_data(0x0c, 0x01);
        write_data(0x0f, 0x00);

        clear();
    };

    void write(uint8_t com, uint8_t show_data);

    void write(int number);

    void clear()
    {
        for (int i = 0; i < 8; i++)
        {
            write_data(i + 1, MAX7219_BIT_DIS);
        }
    }
};

#endif
